#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author  : ganuoxun
# @description : 中间层的数据model

from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel


class WorkListModel(BaseModel):
    """
    中间层作品列表数据结构
    对应表名：cclp_dwm_work
    """
    work_id: str
    work_name: str
    work_alias: Optional[List[str]] = []
    work_series: Optional[str] = ""
    work_subtitle: Optional[str] = ""
    work_age: Optional[str] = ""
    work_intro: Optional[str] = ""
    work_tag: Optional[List[str]] = []
    work_comment: Optional[str] = ""
    preamble: Optional[str] = ""
    author: Optional[List[str]] = []
    author_id: Optional[List[str]] = []
    pub_year: Optional[str] = ""
    publisher: Optional[str] = ""
    page_info: Optional[str] = ""
    file_cnt: Optional[int] = 0
    work_font: Optional[str] = ""
    word_cnt: Optional[int] = 0
    is_wrj: Optional[int] = 0
    type_id: Optional[int] = 0
    library_holdings: Optional[str] = ""
    content_type: Optional[int] = 0
    preview_image: Optional[str] = ""
    fee_schedule: Optional[int] = 0
    free_pages: Optional[int] = 0
    photocopy_supply: Optional[int] = 0
    latest_date: Optional[str] = None
    create_time: Optional[datetime] = None
    is_deprecated: Optional[int] = 0

    def get_dict(self):
        """
        将对象转换为字段格式
        Returns:
            dict
        """
        work_dict = self.__dict__
        work_dict['_id'] = self.work_id
        return work_dict
